

***************
**State Policy Mood: The Importance of Over-Time Dynamics
**Replication Materials
**Peter K. Enns and Julianna Koch
**State Politics and Policy Quarterly
**Generate Values for Figure 1
***************

cd ""

use "EnnsKochSPPQ2015.dta", clear

**gen standardized variables that range from 0 to 1 for BRFH citizen ideology and Enns and Koch Mood
egen citiideol01 = std01(citi6010)
egen mood01 = std01(mood)


*********************************
**Figure 1: The Over-Time Relationship between Four Measures of State Policy and the Enns & Koch and BRFH Measures of State Policy Mood
*********************************
xtset statenum year
*********************************
**Subfigure C: Health Expenditure
*********************************
*First Differences because no evidence of cointegration
*E&K
xi: xtpcse d.health_exp dl2.mood01 i.statename year
*BRFH
xi: xtpcse d.health_exp dl2.citiideol01 i.statename year
*Both
xi: xtpcse d.health_exp dl2.mood01 dl2.citiideol01 i.statename year



************************
*****Estimate LRMs for Subfigures A, B, and D
************************
**Note: Code assumes rhs variables enterred as follows: l.dv, l.var1, l.var2, l.var3 d.var1 d.var2 d.var3
**i.e., lagged values of predictors (long term effects) must follow lagged d.v. (error correction mechanism)

******************************
**Generate lagged variable for each predictor w/ long run effect
******************************
foreach x in taxpercapadj afdctanf_ben_adj policyscore_lib mood01 citiideol01 {
gen l_`x' = l.`x'
gen l2_`x' = l2.`x'
}

*Generate datafile to save results:
postfile pfile str16(dv) str16(iv) lrm se_lrm t lrm_low lrm_hi using "LRM_tax", replace

*****************
**Subfigure A: Tax Revenue
*****************
*Mood lagged 1 year because tax data follow fiscal year, ending in June of Calendar year

foreach v in taxpercapadj {

*E&K
xi: xtpcse d.`v' l_`v' l2_mood01 dl.mood01 i.statename year 
matrix vcov =e(V)
*gen local variable of value 1
local i = 1
*loop over variables for which we will calculate a long term effect
foreach x in l2_mood01 {
*include a counter for the number of long term effects to be calculated (i.e., "foreach i in 1/3 {" indicates 3 long term effects

sum `x' if e(sample)
local lrm = _b[`x']/abs(_b[l_`v'])
local selrm = sqrt(((1/(_b[l_`v']^2))*(_se[`x']^2))+((_b[`x']^2)/(_b[l_`v']^4)*(_se[l_`v']^2))-(2*(_b[`x']/(_b[l_`v']^3))*(vcov[(`i'+1),1])))
*add 1 to i each loop, so appropriate element of vcov is identified.
local i = `i' + 1
post pfile  ("`v'") ("`x'") (`lrm') (`selrm') (`lrm'/`selrm') (`lrm'-(1.96*`selrm')) (`lrm'+(1.96*`selrm'))
}

*BRFH
xi: xtpcse d.`v' l_`v' l2_citiideol01 dl.citiideol01 i.statename year
matrix vcov =e(V)
*gen local variable of value 1
local i = 1
*loop over variables for which we will calculate a long term effect
foreach x in l2_citiideol01 {
*include a counter for the number of long term effects to be calculated (i.e., "foreach i in 1/3 {" indicates 3 long term effects

sum `x' if e(sample)
local lrm = _b[`x']/abs(_b[l_`v'])
local selrm = sqrt(((1/(_b[l_`v']^2))*(_se[`x']^2))+((_b[`x']^2)/(_b[l_`v']^4)*(_se[l_`v']^2))-(2*(_b[`x']/(_b[l_`v']^3))*(vcov[(`i'+1),1])))
*add 1 to i each loop, so appropriate element of vcov is identified.
local i = `i' + 1
post pfile  ("`v'") ("`x'") (`lrm') (`selrm') (`lrm'/`selrm') (`lrm'-(1.96*`selrm')) (`lrm'+(1.96*`selrm'))
}
*Both
xi: xtpcse d.`v' l_`v' l2_mood01 l2_citiideol01 dl.mood01 dl.citiideol01 i.statename year
matrix vcov =e(V)
*gen local variable of value 1
local i = 1
*loop over variables for which we will calculate a long term effect
foreach x in l2_mood01 l2_citiideol01 {
*include a counter for the number of long term effects to be calculated (i.e., "foreach i in 1/3 {" indicates 3 long term effects

sum `x' if e(sample)
local lrm = _b[`x']/abs(_b[l_`v'])
local selrm = sqrt(((1/(_b[l_`v']^2))*(_se[`x']^2))+((_b[`x']^2)/(_b[l_`v']^4)*(_se[l_`v']^2))-(2*(_b[`x']/(_b[l_`v']^3))*(vcov[(`i'+1),1])))
*add 1 to i each loop, so appropriate element of vcov is identified.
local i = `i' + 1
post pfile  ("`v'") ("`x'") (`lrm') (`selrm') (`lrm'/`selrm') (`lrm'-(1.96*`selrm')) (`lrm'+(1.96*`selrm'))
}
}
postclose pfile


************************
*****Subfigures B and D: Welfare and Policy Priority Scores
**Health Expenditure not included because not cointegrated (estimate first differences model)
************************
*Generate datafile to save results:
postfile pfile str16(dv) str16(iv) lrm se_lrm t lrm_low lrm_hi using "LRM", replace

foreach v in afdctanf_ben_adj policyscore_lib {

*E&K
xi: xtpcse d.`v' l_`v' l_mood01 d.mood01 i.statename year 
matrix vcov =e(V)
*gen local variable of value 1
local i = 1
*loop over variables for which we will calculate a long term effect
foreach x in l_mood01 {
*include a counter for the number of long term effects to be calculated (i.e., "foreach i in 1/3 {" indicates 3 long term effects

sum `x' if e(sample)
local lrm = _b[`x']/abs(_b[l_`v'])
local selrm = sqrt(((1/(_b[l_`v']^2))*(_se[`x']^2))+((_b[`x']^2)/(_b[l_`v']^4)*(_se[l_`v']^2))-(2*(_b[`x']/(_b[l_`v']^3))*(vcov[(`i'+1),1])))
*add 1 to i each loop, so appropriate element of vcov is identified.
local i = `i' + 1
post pfile  ("`v'") ("`x'") (`lrm') (`selrm') (`lrm'/`selrm') (`lrm'-(1.96*`selrm')) (`lrm'+(1.96*`selrm'))
}

*BRFH
xi: xtpcse d.`v' l_`v' l_citiideol01 d.citiideol01 i.statename year
matrix vcov =e(V)
*gen local variable of value 1
local i = 1
*loop over variables for which we will calculate a long term effect
foreach x in l_citiideol01 {
*include a counter for the number of long term effects to be calculated (i.e., "foreach i in 1/3 {" indicates 3 long term effects

sum `x' if e(sample)
local lrm = _b[`x']/abs(_b[l_`v'])
local selrm = sqrt(((1/(_b[l_`v']^2))*(_se[`x']^2))+((_b[`x']^2)/(_b[l_`v']^4)*(_se[l_`v']^2))-(2*(_b[`x']/(_b[l_`v']^3))*(vcov[(`i'+1),1])))
*add 1 to i each loop, so appropriate element of vcov is identified.
local i = `i' + 1
post pfile  ("`v'") ("`x'") (`lrm') (`selrm') (`lrm'/`selrm') (`lrm'-(1.96*`selrm')) (`lrm'+(1.96*`selrm'))
}
*Both
xi: xtpcse d.`v' l_`v' l_mood01 l_citiideol01 d.mood01 d.citiideol01 i.statename year
matrix vcov =e(V)
*gen local variable of value 1
local i = 1
*loop over variables for which we will calculate a long term effect
foreach x in l_mood01 l_citiideol01 {
*include a counter for the number of long term effects to be calculated (i.e., "foreach i in 1/3 {" indicates 3 long term effects

sum `x' if e(sample)
local lrm = _b[`x']/abs(_b[l_`v'])
local selrm = sqrt(((1/(_b[l_`v']^2))*(_se[`x']^2))+((_b[`x']^2)/(_b[l_`v']^4)*(_se[l_`v']^2))-(2*(_b[`x']/(_b[l_`v']^3))*(vcov[(`i'+1),1])))
*add 1 to i each loop, so appropriate element of vcov is identified.
local i = `i' + 1
post pfile  ("`v'") ("`x'") (`lrm') (`selrm') (`lrm'/`selrm') (`lrm'-(1.96*`selrm')) (`lrm'+(1.96*`selrm'))
}
}
postclose pfile
drop citiideol01- _Istatename_50


